
/*******************************************************************************
 * Universidad del Valle de Guatemala
 * Algoritmos y estructuras de datos
 * Karen Tojin   08091
 * Fecha: 02 de Septiembre 2009
 * Descricion: Implementación de las colas con prioridad con uso de HEAP
 ***************************************************************************** */
/**
 *
 * @author karenAndy
 */
import java.util.Scanner;

public class Driver {

    public static void main(String[] args) {

        //Size of the heaps
        final int size = 1000;
        int op = 0;
        Scanner input = new Scanner(System.in);

        JFCPriorityQueue<Integer> JFCQueue = new JFCPriorityQueue(size);    //Priority Queue from the JCF
        HeapPriorityQueue<Integer> HeapQueue = new HeapPriorityQueue(size);  //Priority Queue from the heap created using vectors

        int randomNums[] = new int[size];   //Array for the random numbers created
        int mayor, menor = 0;


        //Main Menu
        do {
            System.out.println("\t\t.::: Priority Queue :::.");
            System.out.println();
            System.out.println("1. Generar queue con JFC y Heap proppio");
            System.out.println("2. Salir del programa");

            System.out.print("\nIngrese la opcion que desea realizar: ");
            try {
                op = input.nextInt();
            } catch (Exception excep) {
                System.out.print("\nOpción inválida");
                op = 2;
            }
            //Defensive programming
            while (op < 1 || op > 2) {
                System.out.print("\nOpción incorrecta. Ingrese la opcion que desea realizar: ");
                op = input.nextInt();
            }
            switch (op) {
                //En caso de que la opción sea generar una nueva PriorityQueue
                case 1: {
                    //To initialize the both of the heaps
                    for (int i = 0; i < 1000; i++) {
                        randomNums[i] = (int) (Math.random() * 9999 + 1);
                        JFCQueue.Add(randomNums[i]);
                        HeapQueue.Add(randomNums[i]);
                    }
                    //To work with the JFC heap
                    System.out.println("\nPriorityQueue de JCF: ");
                    mayor = JFCQueue.Remove();
                    while (!JFCQueue.Empty()) {
                        menor = JFCQueue.Remove();
                    }
                    System.out.println("Mayor: " + mayor);
                    System.out.println("Menor: " + menor);

                    //To work with the heap created with vectors
                    System.out.println("\nPriorityQueue de Heap Propio: ");
                    mayor = HeapQueue.Remove();
                    while (!HeapQueue.Empty()) {
                        menor = HeapQueue.Remove();
                    }
                    System.out.println("Mayor: " + mayor);
                    System.out.println("Menor: " + menor);
                }
                break;
            }
        } //Until the exit option is selected
        while (op != 2);

        //Goodbay message
        System.out.println("\n\t.::Gracias por usar este programa::.");
    }
}
